package cn.yll.api.user.service;

import cn.yll.api.user.request.UserExtendModifyRequest;
import cn.yll.api.user.response.UserExtendResponse;
import cn.yll.common.exception.BsErrEnum;
import cn.yll.common.exception.BsException;
import cn.yll.common.module.RestModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 服务降级处理类
 * @author yangll
 */
@Slf4j
@Component
public class RemoteUserExtendFeignFallbackFactory implements FallbackFactory<RemoteUserExtendFeignService> {
    @Override
    public RemoteUserExtendFeignService create(Throwable cause) {
        return new RemoteUserExtendFeignService() {
            @Override
            public RestModel<Boolean> modifyByUserId(UserExtendModifyRequest modifyRequest) {
                log.info("~~~~~~~~~openfeign fallback~~~~~~~~", cause.getCause());
                throw new BsException(BsErrEnum.RPC_ERROR);
            }

            @Override
            public RestModel<UserExtendResponse> getUserExtendById(Long id) {
                log.info("~~~~~~~~~openfeign fallback~~~~~~~~", cause.getCause());
                throw new BsException(BsErrEnum.RPC_ERROR);
            }

            @Override
            public RestModel<UserExtendResponse> getUserExtendByUserId(Long userId) {
                log.info("~~~~~~~~~openfeign fallback~~~~~~~~", cause.getCause());
                throw new BsException(BsErrEnum.RPC_ERROR);
            }

            @Override
            public RestModel<UserExtendResponse> getByIdNo(String idNo) {
                log.info("~~~~~~~~~openfeign fallback~~~~~~~~", cause.getCause());
                throw new BsException(BsErrEnum.RPC_ERROR);
            }

            @Override
            public RestModel<UserExtendResponse> getByEmail(String email) {
                log.info("~~~~~~~~~openfeign fallback~~~~~~~~", cause.getCause());
                throw new BsException(BsErrEnum.RPC_ERROR);
            }
        };
    }
}
